package com.webtest.demo;

import java.util.List;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import bsh.This;
import io.appium.java_client.AppiumBy;
import io.appium.java_client.android.AndroidDriver;

public class CrossearthPage {

	AndroidDriver  driver;
	BaseAction action;
	
	public CrossearthPage(AndroidDriver driver) {
		this.driver = driver;
		this.action= new BaseAction(driver);
	}
	
	

	//一、点击播放按钮后的软件的登录页面
	//1.点击快速登陆
	public WebElement quickLogin() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/quickLoginBtn"));
	}
	
	//2.输入账户名
	public WebElement accountName() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='请输入账户名']"));
	}
	
	//3.输入账户名后再查看账户名
	public WebElement checkAccountname() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/userEdit"));
	}
	
	public WebElement selectAccountname() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='zhuying01']"));
	}
	
	//4.输入密码
	public WebElement homepagePassWord() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='请输入密码']"));
	}
	
	//5.输入密码后查看密码
	public WebElement checkPassWord() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/passwordEdit"));
	}

	public WebElement forgotPassword() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/forgetButton"));
	}	
	
	//7.点击注册
	public WebElement register() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/registerBtn"));
	}	
	//8.点击登录
	public WebElement login() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/loginBtn"));
	}	
	
	
	//二、注册页面
	//1.注册页面，点击返回登录页面
	public WebElement registrationbackLoginPage() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/backButton"));
	}	
	
	//2.注册页面，输入邮箱
	public WebElement registrationpageEmail() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='邮箱注册']"));
	}
	//邮箱输入后检查
	public WebElement checkregistrationpageEmail() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/emailEditText"));
	}
	//3.注册页面，点击发送
	public WebElement registrationpageSend() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/emailButton"));
	}	
	//4.注册页面，输入验证码
	public WebElement registrationpageCaptcha() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='验证码']"));
	}
	//输入验证码后检查
	public WebElement checkregistrationpageCaptcha() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/verificationCodeEditText"));
	}
	//5.输入昵称
	public WebElement nickname() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='昵称']"));
	}
	//输入昵称后检查
	public WebElement checknickname() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/usernameEditText"));
	}
	//6.输入密码
	public WebElement registrationpagePassword() {
		return driver.findElement(AppiumBy
				.xpath("//android.widget.EditText[@text='密码']"));
	}
	//输入密码后检查
	public WebElement checkregistrationpagePassword() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/passwordEditText"));
	}
	//7.点击注册
	public WebElement registration() {
		return driver.findElement(AppiumBy
				.id("com.software.crossearth:id/registerButton"));
	}

	//一、点击播放按钮后的软件的登录页面
	//6.不输入用户名及密码直接登录
	public void directlyLogin() throws InterruptedException {
		action.click(this.startCrossearth());
		action.click(this.login());
	}
	
	//7.使用快捷键Ctrl+C/V复制粘贴用户名及密码进行登录
	public void shortcutkeyLogin() throws InterruptedException {
		//先进行Ctrl+C复制操作
		action.click(this.startCrossearth());
		action.typeAndClear(this.accountName(), "zhuying01");		
		action.getPositionAndSize(driver, AppiumBy
				.id("com.software.crossearth:id/userEdit"));
		action.longPress(this.selectAccountname(),3);
		action.click(this.homepagePassWord());
		action.pressctrlkey('V');
		action.click(this.login());
	}
	
	//8.输入正确用户名和密码进行登录
	public void rightLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "zhuying01");		
		action.typeAndClear(this.checkPassWord(), "zhuying01");	
		action.click(this.login());
	}
	
	//9.用户名和密码均输入两次回车进行登录
	public void doubleenterLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "");	
//		action.pressEnterKey();
//		Thread.sleep(500);
		action.pressEnterKey();
		Thread.sleep(500);
		action.typeAndClear(this.checkPassWord(), "");	
		action.pressTabKey();
		action.click(this.login());
	}
	
	//10.输入用户名和密码步骤间插入点击忘记密码操作
	public void insertLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "zhuying01");		
		action.click(this.forgotPassword());
		action.navigateBack();
		action.typeAndClear(this.checkPassWord(), "zhuying01");	
		action.click(this.login());
	}	
	
	//11.用户名输入特殊字符@#$%进行登录
	public void specialLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "");		
		action.pressctrlkey('@');
		action.pressctrlkey('#');
		action.pressctrlkey('$');
		action.pressctrlkey('%');
		action.typeAndClear(this.checkPassWord(), "zhuying01");	
		action.click(this.login());
	}
	
	//12.用户名输入脚本函数进行登录
	public void scriptLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "<script>alert('用户名')</script>");		
		action.typeAndClear(this.checkPassWord(), "zhuying01");	
		action.click(this.login());
	}
	
	//13.用户名输入汉字+数字组合朱颖6666进行登录
	public void combineLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "朱颖6666");		
		action.typeAndClear(this.checkPassWord(), "朱颖6666");	
		action.click(this.login());
	}
	
	//14.密码输入空格进行登录
	public void spaceLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "zhuying01");		
		action.typeAndClear(this.checkPassWord(), " ");	
		action.click(this.login());
	}	
	
	//15.输入未注册的用户名进行登录
	public void notregisteredLogin() throws InterruptedException {
		action.typeAndClear(this.checkAccountname(), "zhuying100");		
		action.typeAndClear(this.checkPassWord(), "123456");	
		action.click(this.login());
	}
	
	
	//二、注册页面
	//16.不输入任何文本直接注册
	public void directlyRegistration() throws InterruptedException {
		action.click(this.register());
		action.click(this.registration());
	}
	
	//17.输入正确邮箱、昵称和密码进行注册
	public void rightRegistration() throws InterruptedException {
		action.typeAndClear(this.registrationpageEmail(), "zhuying01@01.com");		
		action.typeAndClear(this.registrationpageCaptcha(), "123456");	
		action.typeAndClear(this.nickname(), "zhuying01");	
		action.typeAndClear(this.registrationpagePassword(), "zhuying01");	
		action.click(this.registration());
	}
	
	//18.输入邮箱、昵称和密码步骤间插入返回操作进行注册
	public void insertRegistration() throws InterruptedException {
		//action.click(this.register());
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying02@02.com");	
		action.navigateBack();
		action.click(this.register());
		action.typeAndClear(this.registrationpageEmail(), "zhuying02@02.com");	
		action.typeAndClear(this.registrationpageCaptcha(), "123456");	
		action.typeAndClear(this.nickname(), "zhuying02");	
		action.typeAndClear(this.registrationpagePassword(), "zhuying02");	
		action.click(this.registration());
	}
	
	//19.密码输入特殊字符+空格+数字+汉字组合*& 23朱颖进行登录
	public void combineRegistration() throws InterruptedException {
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying03@03.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "zhuying03");	
		action.typeAndClear(this.checkregistrationpagePassword(), "");	
		action.pressctrlkey('*');
		action.pressctrlkey('&');
		action.pressctrlkey(' ');
		action.type(this.checknickname(), "23");	
		action.click(this.registration());
	}
	
	//20.填完信息后重新覆盖信息进行注册
	public void coverRegistration() throws InterruptedException {
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying04@04.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "zhuying04");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying04");	
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying02@04.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "222222");	
		action.typeAndClear(this.checknickname(), "zhuying04");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying04");	
		action.click(this.registration());
	}
	
	//21.昵称输入100个字符
	public void hundredRegistration() throws InterruptedException {
		//action.click(this.register());
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying05@05.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "昵称昵称昵称昵称昵称昵称昵称昵称昵称昵称"
				+ "昵称昵称昵称昵称昵称昵称昵称昵称昵称昵称"
				+ "昵称昵称昵称昵称昵称昵称昵称昵称昵称昵称"
				+ "昵称昵称昵称昵称昵称昵称昵称昵称昵称昵称"
				+ "昵称昵称昵称昵称昵称昵称昵称昵称昵称昵称");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying05");	
		action.click(this.checkregistrationpagePassword());
		Thread.sleep(500);
		action.pressTabKey();
		action.click(this.registration());
	}
	
	//22.邮箱及昵称输入脚本函数进行注册
	public void scriptRegistration() throws InterruptedException {
		action.typeAndClear(this.checkregistrationpageEmail(), "<script>alert('邮箱')</script>");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "<script>alert('昵称')</script>");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying06");	
		action.click(this.registration());
	}
	
	//23.昵称输入特殊字符*&……%
	public void specialRegistration() throws InterruptedException {
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying07@07.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "*&……%");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying07");	
		action.click(this.registration());
	}
	
	//24.注册已经用过的邮箱
	public void existRegistration() throws InterruptedException {
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying01@01.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "zhuying01");	
		action.typeAndClear(this.checknickname(), "zhuying01");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying01");	
		action.click(this.registration());
	}
	
	//25.注册已经存在的用户昵称
	public void nickRegistration() throws InterruptedException {
		//action.click(this.register());
		action.typeAndClear(this.checkregistrationpageEmail(), "zhuying01@01.com");		
		action.typeAndClear(this.checkregistrationpageCaptcha(), "123456");	
		action.typeAndClear(this.checknickname(), "zhuying01");	
		action.typeAndClear(this.checkregistrationpagePassword(), "zhuying01");	
	
		action.click(this.registration());
		action.navigateBack();
	}

}
